package com.trkj.service.wdm;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.trkj.dao.wdm.EmpPassDAO;
import com.trkj.dao.wdm.JobseekersRegister3DAO_lxl;
import com.trkj.dao.wdm.LaborTurnoverDao;
import com.trkj.dao.wdm.PositionDao;
import com.trkj.dao.wdm.StaffInformationDAO;
import com.trkj.mybatisdao.HireStaffMapper;
import com.trkj.pojo.Emppass;
import com.trkj.pojo.LaborTurnover;
import com.trkj.pojo.Position;
import com.trkj.pojo.StaffInformation;
import com.trkj.service.ServiceException;

@Service
public class HireStaffService {
	@Autowired
	private HireStaffMapper hireMapper;
	@Autowired
	private StaffInformationDAO sdao;
	@Autowired
	private EmpPassDAO emoDao;
	@Autowired
	private PositionDao pDao;
	@Autowired
	private JobseekersRegister3DAO_lxl jobDao;
	@Autowired
	private LaborTurnoverDao laborDao;
	
	
	
	public JSONArray findAll(){
		return hireMapper.findAll();
	}
	
	/**
	 * 录用
	 * @param id
	 * @param id2
	 * @param name
	 */
	public void addStaff(Long id,Long id2,String name) throws ServiceException{
		try { 
			Position p = pDao.findOne(id2);
			
			StaffInformation staff = new StaffInformation();
			staff.setStainName(name);
			staff.setPosition(p);
			
			Emppass e = new Emppass();
			e.setPassPwd("123456");
			e.setStaffInformation(staff);
			sdao.save(staff);
			emoDao.save(e);
			jobDao.delete(id);
			LaborTurnover la = new LaborTurnover();
			la.setStaffInformation(staff);
			la.setVoluntaryTurnover(new BigDecimal(0));
			laborDao.save(la);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
}
